namespace DeviceCommons.DeviceMessages.Serialization
{
    /// <summary>
    /// 解析上下文
    /// 用于在解析过程中传递上下文信息
    /// </summary>
    public class ParsingContext
    {
        /// <summary>
        /// 当前正在解析的设备类型
        /// </summary>
        public byte? CurrentDeviceType { get; set; }

        /// <summary>
        /// 解析深度
        /// </summary>
        public int ParsingDepth { get; set; }

        /// <summary>
        /// 是否启用快速解析
        /// </summary>
        public bool EnableFastParsing { get; set; } = true;

        /// <summary>
        /// 创建新的解析上下文
        /// </summary>
        /// <param name="deviceType">设备类型</param>
        /// <returns>新的解析上下文</returns>
        public static ParsingContext Create(byte? deviceType = null)
        {
            return new ParsingContext
            {
                CurrentDeviceType = deviceType,
                ParsingDepth = 0,
                EnableFastParsing = true
            };
        }

        /// <summary>
        /// 创建子上下文
        /// </summary>
        /// <returns>子解析上下文</returns>
        public ParsingContext CreateChild()
        {
            return new ParsingContext
            {
                CurrentDeviceType = this.CurrentDeviceType,
                ParsingDepth = this.ParsingDepth + 1,
                EnableFastParsing = this.EnableFastParsing
            };
        }
    }
}
